# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models

from wlmodels.codes.models import ELBaseModel, EntIdable
from wlmodels.company.models import ELPost


# 欠税记录
class ELOwtax(EntIdable):
    REGNO = models.CharField("工商注册号", max_length=30, null=True)
    cpwsid = models.CharField('裁判文书ID', max_length=50, null=True)
    pubdate = models.DateField('发布时间', null=True, blank=True)
    taxdepar = models.CharField("税务机关", max_length=100, null=True, blank=True)
    tax_id = models.CharField("纳税识别号", max_length=36, null=True, blank=True)
    tax_type = models.CharField("税种", max_length=30, null=True, blank=True)
    tax_unpaid_amount = models.CharField("欠税金额", max_length=20, null=True, blank=True)
    case_details = models.TextField("详情", null=True, blank=True)

    class Meta:
        verbose_name_plural = '欠税记录'
        verbose_name = '欠税记录'
        db_table = 'law_owtax'

    def __unicode__(self):
        return u"欠税记录-%s" % self.pk

    def save(self, *args, **kwargs):
        if self.entid_id is None and self.REGNO:
            the_ents = (ELPost.object.filter(REGNO=self.REGNO).values_list("entid", flat=True))
            if len(the_ents):
                self.entid_id = the_ents[0]
        super(ELOwtax, self).save(*args, **kwargs)


# 税务非正常户
class ELUnnortax(EntIdable):
    REGNO = models.CharField("工商注册号", max_length=30, null=True, blank=True)
    case_id_unnortax = models.CharField('案件ID', max_length=50, null=True)
    pubdate = models.DateField('认定时间', null=True, blank=True)
    taxdepar = models.CharField("税务机关", max_length=100, null=True, blank=True)
    tax_id = models.CharField("纳税识别号", max_length=36, null=True, blank=True)
    pubperi = models.CharField("发布期", max_length=20, null=True, blank=True)
    case_details = models.TextField("详情", null=True, blank=True)

    class Meta:
        verbose_name = '税务非正常户'
        verbose_name_plural = '税务非正常户'
        db_table = 'law_unnortax'

    def __unicode__(self):
        return u"税务非正常户%s" % self.pk

    def save(self, *args, **kwargs):
        if self.entid_id is None and self.REGNO:
            the_ents = (ELPost.object.filter(REGNO=self.REGNO).values_list("entid", flat=True))
            if len(the_ents):
                self.entid_id = the_ents[0]
        super(ELUnnortax, self).save(*args, **kwargs)


# 经营异常
class ELUnopera(EntIdable):
    REGNO = models.CharField("工商注册号", max_length=30, null=True, blank=True)
    case_id_unopera = models.CharField('案件ID', max_length=30, null=True)
    depar = models.CharField('做出决定机关', max_length=128, null=True)
    indate = models.DateField('列入日期', null=True, blank=True)
    reason = models.TextField('列入原因', null=True, blank=True)
    case_details = models.TextField("详情", null=True, blank=True)

    class Meta:
        verbose_name = '经营异常'
        verbose_name_plural = '经营异常'
        db_table = 'law_unopera'

    def __unicode__(self):
        return u"经营异常-%s" % self.pk

    def save(self, *args, **kwargs):
        if self.entid_id is None and self.REGNO:
            the_ents = (ELPost.object.filter(REGNO=self.REGNO).values_list("entid", flat=True))
            if len(the_ents):
                self.entid_id = the_ents[0]
        super(ELUnopera, self).save(*args, **kwargs)


# 裁判文书
class ELCpws(EntIdable):
    REGNO = models.CharField("工商注册号", max_length=30, null=True, blank=True)
    case_id_judg = models.CharField('案件ID', max_length=30, null=True)
    judgdate = models.DateField('判决时间', null=True, blank=True)
    case_title = models.CharField('标题', max_length=128, null=True, blank=True)
    court = models.CharField('法院名称', max_length=128, null=True, blank=True)
    case_no_judg = models.CharField('案号', max_length=30, null=True, blank=True)
    judgcase_reason = models.TextField('案由', null=True, blank=True)
    case_details = models.TextField("详情", null=True, blank=True)

    class Meta:
        verbose_name_plural = '裁判文书'
        verbose_name = '裁判文书'
        db_table = 'law_cpws'

    def __unicode__(self):
        return u"裁判文书-%s" % self.pk

    def save(self, *args, **kwargs):
        if self.entid_id is None and self.REGNO:
            the_ents = (ELPost.object.filter(REGNO=self.REGNO).values_list("entid", flat=True))
            if len(the_ents):
                self.entid_id = the_ents[0]
        super(ELCpws, self).save(*args, **kwargs)


# 开庭公告
class ELKtgg(EntIdable):
    REGNO = models.CharField("工商注册号", max_length=30, null=True, blank=True)
    case_id_court = models.CharField('案件ID', max_length=30, null=True)
    courdate = models.DateField('开庭日期', null=True, blank=True)
    court = models.CharField('法院名称', max_length=128, null=True, blank=True)
    coutcase_reason = models.TextField('案由', null=True, blank=True)
    case_parties = models.CharField('当事人', max_length=128, null=True, blank=True)
    case_details = models.TextField("详情", null=True, blank=True)

    class Meta:
        verbose_name_plural = '开庭公告'
        verbose_name = '开庭公告'
        db_table = 'law_ktgg'

    def __unicode__(self):
        return u"开庭公告-%s" % self.pk

    def save(self, *args, **kwargs):
        if self.entid_id is None and self.REGNO:
            the_ents = (ELPost.object.filter(REGNO=self.REGNO).values_list("entid", flat=True))
            if len(the_ents):
                self.entid_id = the_ents[0]
        super(ELKtgg, self).save(*args, **kwargs)


# 司法协助
class ELLawAid(EntIdable):
    REGNO = models.CharField("工商注册号", max_length=30, null=True, blank=True)
    case_id_aid = models.CharField('案件ID', max_length=30, null=True)
    pubdate = models.DateField('公示日期', null=True, blank=True)
    aidcase_assior_ent = models.CharField('股权所在企业', max_length=128, null=True, blank=True)
    aidcase_name = models.CharField('被执行人', max_length=30, null=True, blank=True)
    aidcase_assiee = models.CharField('受让人', max_length=30, null=True, blank=True)
    aidcase_matt = models.TextField('执行事项', null=True, blank=True)
    amount = models.CharField('股权数额', max_length=20, null=True, blank=True)
    case_details = models.TextField("详情", null=True, blank=True)

    class Meta:
        verbose_name_plural = '司法协助'
        verbose_name = '司法协助'
        db_table = 'law_aid'

    def __unicode__(self):
        return u"司法协助-%s" % self.pk

    def save(self, *args, **kwargs):
        if self.entid_id is None and self.REGNO:
            the_ents = (ELPost.object.filter(REGNO=self.REGNO).values_list("entid", flat=True))
            if len(the_ents):
                self.entid_id = the_ents[0]
        super(ELLawAid, self).save(*args, **kwargs)


# 涉诉公告
class ELLawSS(EntIdable):
    REGNO = models.CharField("工商注册号", max_length=30, null=True, blank=True)
    case_id_law = models.CharField('案件ID', max_length=30, null=True)
    pubdate = models.DateField('公告日期', null=True, blank=True)
    case_type = models.CharField('公告类型', max_length=20, null=True, blank=True)
    case_court = models.CharField('公告人', max_length=20, null=True, blank=True)
    case_parties = models.CharField('当事人', max_length=128, null=True, blank=True)
    case_details = models.TextField("详情", null=True, blank=True)

    class Meta:
        verbose_name_plural = '涉诉公告'
        verbose_name = '涉诉公告'
        db_table = 'law_ss'

    def __unicode__(self):
        return u"涉诉公告-%s" % self.pk

    def save(self, *args, **kwargs):
        if self.entid_id is None and self.REGNO:
            the_ents = (ELPost.object.filter(REGNO=self.REGNO).values_list("entid", flat=True))
            if len(the_ents):
                self.entid_id = the_ents[0]
        super(ELLawSS, self).save(*args, **kwargs)


# 诉讼当事人集合
class ELPartys(ELBaseModel):
    title = models.CharField('当事人名称', max_length=30, null=True)
    nickname = models.TextField('当事人称号', null=True, blank=True)
    partytype = models.TextField('当事人类型', null=True, blank=True)
    birthday = models.DateField('当事人生日', null=True, blank=True)
    lawoffice = models.TextField('律师事务所', null=True, blank=True)
    status = models.TextField('当事人立场', null=True, blank=True)
    idcardno = models.CharField('当事人身份证号码', max_length=18, null=True, blank=True)
    lawyer = models.TextField('委托辩护人', null=True, blank=True)

    class Meta:
        verbose_name = '诉讼当事人'
        verbose_name_plural = '诉讼当事人'
        db_table = 'law_partys'

    def __unicode__(self):
        return u"%s" % self.title


# 执行公告
class ELZxgg(ELBaseModel):
    title = models.TextField('标题', null=True)
    zxggid = models.CharField('执行公告ID', max_length=50, null=True)
    sorttime = models.DateTimeField('立案时间', null=True, blank=True)
    body = models.TextField('内容', null=True, blank=True)
    status = models.TextField('执行状态', null=True, blank=True)
    pname = models.CharField('被执行人姓名', max_length=30, null=True, blank=True)
    court = models.TextField('执行法院名称', null=True, blank=True)
    proposer = models.TextField('申请人', null=True, blank=True)
    caseno = models.CharField('案号', max_length=30, null=True, blank=True, db_index=True)
    casestate = models.TextField('案件状态', null=True, blank=True)
    idcardno = models.TextField('身份证/组织机构代码', null=True, blank=True)
    execmonty = models.TextField('执行标的', null=True, blank=True)

    class Meta:
        verbose_name = '执行公告'
        verbose_name_plural = '执行公告'
        db_table = 'law_zxgg'

    def __unicode__(self):
        return u"%s" % self.zxggid


# 失信公告
class ELSxgg(ELBaseModel):
    sxggid = models.CharField('失信公告ID', max_length=50, null=True)
    sorttime = models.DateTimeField('立案时间', null=True, blank=True)
    pname = models.CharField('被执行人姓名', max_length=30, null=True, blank=True)
    sex = models.CharField('性别', max_length=1, choices=(("0", "女"), ("1", "男")), null=True, blank=True)
    lxqk = models.TextField('被执行人的履行情况', null=True, blank=True)
    yjcode = models.TextField('执行依据文号', null=True, blank=True)
    court = models.TextField('执行法院名称', null=True, blank=True)
    idcardno = models.TextField('身份证/组织机构代码', null=True, blank=True)
    yjdw = models.TextField('做出执行依据单位', null=True, blank=True)
    jtqx = models.TextField('失信被执行人行为具体情形', null=True, blank=True)
    yiwu = models.TextField('生效法律文书确定的义务', null=True, blank=True)
    age = models.SmallIntegerField('年龄', null=True, blank=True)
    province = models.TextField('省份', null=True, blank=True)
    caseno = models.CharField('案号', max_length=30, null=True, blank=True, db_index=True)
    posttime = models.DateTimeField('发布时间', null=True, blank=True)

    class Meta:
        verbose_name = '失信公告'
        verbose_name_plural = '失信公告'
        db_table = 'law_sxgg'

    def __unicode__(self):
        return u"%s" % self.sxggid


# 法院公告
class ELFygg(ELBaseModel):
    pname = models.CharField('当事人', max_length=30, null=True)
    fyggid = models.CharField('法院公告ID', max_length=50, null=True)
    sorttime = models.DateTimeField('发布时间', null=True, blank=True)
    body = models.TextField('公告内容', null=True, blank=True)
    court = models.TextField('法院名称', null=True, blank=True)
    ggtype = models.TextField('公告类型', null=True, blank=True)
    layout = models.TextField('版面', null=True, blank=True)

    class Meta:
        verbose_name = '法院公告'
        verbose_name_plural = '法院公告'
        db_table = 'law_fygg'

    def __unicode__(self):
        return u"%s" % self.fyggid


# 网贷黑名单
class ELWdhmd(ELBaseModel):
    wdhmdid = models.CharField('网贷黑名单ID', max_length=50, null=True)
    sorttime = models.DateField('贷款时间', null=True, blank=True)
    pname = models.CharField('姓名', max_length=30, null=True, blank=True)
    sex = models.CharField('性别', max_length=1, choices=(("0", "女"), ("1", "男")), null=True, blank=True)
    phone = models.TextField('居住电话', null=True, blank=True)
    updatetime = models.DateTimeField('信息更新时间', null=True, blank=True)
    execourt = models.TextField('执行法院', null=True, blank=True)
    whfx = models.TextField('未还/罚息', null=True, blank=True)
    idcardno = models.TextField('身份证号', null=True, blank=True)
    bitthplace = models.TextField('籍贯地址', null=True, blank=True)
    bjbx = models.TextField('本金/本息', null=True, blank=True)
    caseno = models.CharField('案号', max_length=30, null=True, blank=True, db_index=True)
    address = models.TextField('居住地址', null=True, blank=True)
    email = models.EmailField('邮箱地址', null=True, blank=True)
    age = models.SmallIntegerField('年龄', null=True, blank=True)
    datasource = models.TextField('数据来源单位名称', null=True, blank=True)
    yhje = models.TextField('已还金额', null=True, blank=True)
    mobile = models.TextField('手机号', null=True, blank=True)

    class Meta:
        verbose_name = '网贷黑名单'
        verbose_name_plural = '网贷黑名单'
        db_table = 'law_wdhmd'

    def __unicode__(self):
        return u"%s" % self.wdhmdid


# 案件流程
class ELAjlc(ELBaseModel):
    ajlcid = models.CharField('案件流程ID', max_length=50, null=True)
    member = models.TextField('法庭成员', null=True, blank=True)
    sorttime = models.DateTimeField('立案时间', null=True, blank=True)
    casetype = models.TextField('案件类别', null=True, blank=True)
    body = models.TextField('内容', null=True, blank=True)
    trialprocedure = models.TextField('审理程序', null=True, blank=True)
    court = models.TextField('法院名称', null=True, blank=True)
    casecause = models.TextField('案由', null=True, blank=True)
    clerkphone = models.TextField('书记员电话', null=True, blank=True)
    sentencingdate = models.DateField('判决日期', null=True, blank=True)
    organizer = models.TextField('组织单位', null=True, blank=True)
    filingdate = models.DateField('归档日期', null=True, blank=True)
    ajlcstatus = models.TextField('流程状态', null=True, blank=True)
    chiefjudge = models.TextField('主审法官', null=True, blank=True)
    clerk = models.TextField('书记员', null=True, blank=True)
    pname = models.CharField('当事人', max_length=30, null=True, blank=True)
    judge = models.TextField('主审法官', null=True, blank=True)
    actionobject = models.TextField('诉讼标的', null=True, blank=True)
    caseno = models.CharField('案号', max_length=30, null=True, blank=True, db_index=True)
    triallimitdate = models.DateField('审判期限', null=True, blank=True)
    effectivedate = models.DateField('有效日期', null=True, blank=True)

    class Meta:
        verbose_name_plural = '案件流程'
        verbose_name = '案件流程'
        db_table = 'law_ajlc'

    def __unicode__(self):
        return u"%s" % self.ajlcid


# 曝光台
class ELbgt(ELBaseModel):
    bgtid = models.CharField('曝光台ID', max_length=50, null=True)
    sorttime = models.DateField('立案日期', null=True, blank=True)
    body = models.TextField('内容', null=True, blank=True)
    bgdate = models.DateTimeField('曝光时间', null=True, blank=True)
    partytype = models.TextField('当事人类型', null=True, blank=True)
    court = models.TextField('法院名称', null=True, blank=True)
    proposer = models.TextField('申请人', null=True, blank=True)
    idcardno = models.TextField('身份证/组织机构代码', null=True, blank=True)
    casecause = models.TextField('案由', null=True, blank=True)
    unnexemoney = models.TextField('未执行金额', null=True, blank=True)
    address = models.TextField('地址', null=True, blank=True)
    pname = models.CharField('当事人', max_length=30, null=True, blank=True)
    caseno = models.CharField('案号', max_length=30, null=True, blank=True, db_index=True)
    yiju = models.TextField('依据', null=True, blank=True)
    execmoney = models.TextField('标的金额', null=True, blank=True)

    class Meta:
        verbose_name = '曝光台'
        verbose_name_plural = '曝光台'
        db_table = 'law_bgt'

    def __unicode__(self):
        return u"%s" % self.bgtid


# 环保处罚
class ELEpbcf(ELBaseModel):
    epbcfid = models.CharField('环保处罚ID', max_length=50, null=True)
    pname = models.TextField('企业名称', null=True, blank=True)
    sorttime = models.DateField('时间', null=True, blank=True)
    body = models.TextField('内容', null=True, blank=True)
    casetype = models.TextField('案件类型', null=True, blank=True)
    casecause = models.TextField('案由', null=True, blank=True)
    money = models.TextField('涉案金额', null=True, blank=True)
    punishorg = models.TextField('处罚组织', null=True, blank=True)
    yiju = models.TextField('依据', null=True, blank=True)
    punishcontent = models.TextField('处罚内容', null=True, blank=True)
    legalrepresentative = models.TextField('法定代表人', null=True, blank=True)

    class Meta:
        verbose_name = '环保处罚'
        verbose_name_plural = '环保处罚'
        db_table = 'law_epbcf'

    def __unicode__(self):
        return u"%s" % self.epbcfid


# 法律信用信息
class ELLawCredit(ELBaseModel):
    creditid = models.CharField('信用ID', max_length=50, null=True)
    sorttime = models.DateField('时间', null=True, blank=True)
    body = models.TextField('内容', null=True, blank=True)
    authority = models.TextField('权威机构', null=True, blank=True)
    casecause = models.TextField('案由', null=True, blank=True)
    credittype = models.TextField('信用类型', null=True, blank=True)
    pname = models.TextField('当事人', null=True, blank=True)
    caseno = models.CharField('案号', max_length=30, null=True, blank=True, db_index=True)
    idcardno = models.TextField('身份证/组织结构代码', null=True, blank=True)

    class Meta:
        verbose_name_plural = '信用信息'
        verbose_name = '信用信息'
        db_table = 'law_credit'

    def __unicode__(self):
        return u"%s" % self.creditid


# 解析后裁判文书的摘要信息
class ELAbstract(ELBaseModel):
    fee = models.TextField('判决金额', null=True, blank=True)
    sorttime = models.DateTimeField('结案时间', null=True, blank=True)
    casecause = models.TextField('案由', null=True, blank=True)
    partytitle = models.TextField('当事人类型', null=True, blank=True)
    court = models.TextField('受理机构', null=True, blank=True)
    caf = models.TextField('案件受理费', null=True, blank=True)

    class Meta:
        verbose_name = '解析后裁判文书摘要'
        verbose_name_plural = '解析后裁判文书摘要'
        db_table = 'law_abstract'

    def __unicode__(self):
        return u"%s" % self.id
